package com.my.feign;

import com.atguigu.springcloud.entities.Payment;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/*
* fallbackFactory 与 fallback 方法不能同时使用，
* 这个两个方法其实都类似于 Hystrix 的功能，当网络不通时返回默认的配置数据。
* */
@Component
@FeignClient(
        value = "CLOUD-PAYMENT-SERVICE",
        fallbackFactory = TestFeignFallBackFactory.class,
        contextId = "iTestFeignBackFactory"
)
public interface ITestFeignBackFactory {

    String API_PREFIX = "/feign/payment";

    @GetMapping(API_PREFIX + "/findOne")
    R<Payment> findOne(@RequestParam("id") Long id);

    /*
    * 调用默认1秒钟超时 超过会报错
    * 可以在yml中开启配置 超过1秒
    * #设置feign客户端超时时间
        ribbon:
          ReadTimeout: 5000
          ConnectTimeout: 5000
    * */
    @GetMapping(API_PREFIX + "/timeOut")
    R timeOut();

}
